#include "LogProbe.h"
#include <iostream>
#include <fstream>

using namespace std;

LogProbe::LogProbe(string filename)

{
	file.open(filename.c_str(),ofstream::out|ofstream::app);
	if(!file.is_open())
		cout << "BIG ERROR: NAO ABRIU ARQUIVO DE LOG"<< endl;
	else
	{
		cout <<"Abriu Arquivo de log com sucesso";	
		SetTime();		
		string line = "Starting ";
		line += filename;
		line += " Report ";
		GravarLog(line);
	}
}

LogProbe::~LogProbe()
{
	file.close();
}

void LogProbe::SetTime()
{
	Time = time(&Time);	
}

time_t LogProbe::GetTime()
{
	return Time;
}

time_t LogProbe::GetDeltaTime()
{
	time_t now;
	now = time(&now);
	return (now - Time);
}
void LogProbe::GravarLog(string line)
{
	time_t now;
	now= time(&now);
	file << line << "at " << now <<endl;	
}

void LogProbe::GravarLog(string line,time_t intervalo)
{
	file << line << "durou " << intervalo << endl;
}
